/* eslint-disable object-curly-newline,prefer-destructuring */
import React, { Component } from 'react';
import { Form, Row, Col, Icon } from 'antd';
import ShowType from '../Common/ShowType/ShowTypeNew';
import * as commonBusiness from './business/commonBusiness'; /* 单据业务功能 */
import styles from '../../index.less';

const FormItem = Form.Item;

class TabMasterTable extends Component {
  handleToggle = () => {
    this.props.onToggle();
  };

  render() {
    const props = commonBusiness.dealMasterDisabled(this.props);
    const { masterShowConfig, expand, isMasterRender, disabled } = props;
    const formItemLayout = { labelCol: { span: 2 }, wrapperCol: { span: 18 } };
    return (
      <FormItem className={styles.searchMainForm}>
        <Row type="flex" style={{ height: expand ? 'auto' : '100px', overflow: 'hidden' }}>
          {
            masterShowConfig.map((child) => {
              const sMemo = child.sName.toLowerCase().endsWith('memo');
              const iColValue = sMemo ? 21 : child.iColValue * 6; /* 跨度 */
              const iOrder = sMemo ? 100 : child.iOrder > 100 ? 100 : child.iOrder; /* 排序 */
              const showTypeProps = {
                ...this.props,
                showConfig: child,
                formItemLayout: sMemo ? formItemLayout : {},
                textArea: sMemo,
                isRender: isMasterRender !== undefined && isMasterRender[child.sName] !== undefined ? isMasterRender[child.sName] : false,
                disabled: disabled || child.bReadonly || child.specialControl,
              };
              return (
                <Col key={child.sId} span={iColValue} order={iOrder}>
                  <ShowType {...showTypeProps} />
                </Col>
              );
            })
          }
        </Row>
        <button
          className={expand ? styles.collapseB : styles.collapseA}
          onClick={this.handleToggle}
        >
          <span>{expand ? '缩略展示' : '显示全部'}</span><Icon type={expand ? 'up' : 'down'} />
        </button>
      </FormItem>
    );
  }
}

export default TabMasterTable;
